package mongodb

import (
	"go_api/models/mysql"
	"gopkg.in/mgo.v2/bson"
	"log"
	"time"
)

type Assignment struct {
	//MgoModel
	ID        	bson.ObjectId        	`bson:"_id" json:"_id"`
	TaskName  	string   				`bson:"task_name" json:"task_name"`
	Status   	string   				`bson:"status" json:"status"`
	StudentId   int						`bson:"student_id" json:"student_id"`
	Student     mysql.User              `bson:"-" json:"student"`
	Teacher     mysql.User              `bson:"-" json:"teacher"`
	CreatedBy   int						`bson:"created_by" json:"created_by"`
	Meta 		Meta					`bson:"meta" json:"meta"`
	MissionType string   				`bson:"missionType" json:"missionType"`
	FinishedAt 	time.Time          		`bson:"finished_at" json:"finished_at"`
	CreatedAt 	time.Time          		`bson:"created_at" json:"created_at"`
	UpdatedAt  	time.Time            	`bson:"updated_at" json:"updated_at"`
	deletedAt  	time.Time           	`bson:"deleted_at" json:"deleted_at"`
}

type Meta struct {
	Mode		string 					`bson:"mode" json:"mode"`
	Range		[]int					`bson:"range" json:"range"`
	Order		string					`bson:"order" json:"order"`
	RangeCount  int 					`bson:"range_count" json:"range_count"`
	ViewMode	string					`bson:"view_mode" json:"view_mode"`
}


func GetAssignments(pageNum int, pageSize int, maps interface{}) (assignments []*Assignment, err error) {
	err = mgoDb.C("assignments").Find(maps).Skip(pageNum).Limit(pageSize).All(&assignments)
	if err != nil {
		return nil, err
	}
	return assignments, nil
}


func GetArticleTotal(maps interface{}) (count int, err error) {
	count , err = mgoDb.C("assignments").Find(maps).Count()
	if  err != nil {
		log.Fatalf("assignments count err: %v", err)
		return 0, err
	}

	return count, nil
}
